package edu.qd.learn.newchapter.chapter03.work;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * 数组结构
 * Arrays
 *
 * @author 布衣
 */
public class NoteBookArray implements NoteBook {

    private Event[] events;

    private int size;

    public NoteBookArray() {

    }

    public void addEvent(Event event) {
        if (events == null) {
            events = new Event[10];
        }
        //扩容
        if (size == events.length) {
            events = Arrays.copyOf(events, events.length + (events.length >> 1));
        }
        events[size++] = event;
    }

    /**
     * 6大原则  ： 单一 开闭  里氏代替
     *
     * @param title
     * @param data
     * @param content
     */
    public void addEvent(String title, LocalDate data, String content) {
        addEvent(new Event(title, data, content));
    }

    public void list(){
        for(int i = 0; i < size; i++){
            System.out.println(events[i]);
        }
    }

}
